# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=taglib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.11.1
pkgrel=1
pkgdesc="A Library for reading and editing the meta-data of several popular audio formats (mingw-w64)"
arch=('any')
url="https://taglib.github.com"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cppunit")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=(https://taglib.github.io/releases/${_realname}-${pkgver}.tar.gz
        fix-finding-cppunit.patch)
sha256sums=('b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b'
            '460e2dd83e6233145e4980a4c63a400e9e8297980e3cfae910dadefa2475e7d0')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/fix-finding-cppunit.patch
}

build() {
  msg "Build shared version"
  mkdir -p "${srcdir}/build-shared-${MINGW_CHOST}"
  cd "${srcdir}/build-shared-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_BINDINGS=ON \
    -DWITH_ASF=ON \
    -DWITH_MP4=ON \
    ../${_realname}-${pkgver}

  make

  msg "Build static version"
  mkdir -p "${srcdir}/build-static-${MINGW_CHOST}"
  cd "${srcdir}/build-static-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DBUILD_TESTS=ON \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=OFF \
    -DBUILD_BINDINGS=ON \
    -DWITH_ASF=ON \
    -DWITH_MP4=ON \
    ../${_realname}-${pkgver}

  make
}

check() {
    cd "${srcdir}/build-static-${MINGW_CHOST}"

    make check
}

package() {
  cd "${srcdir}/build-static-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  cd "${srcdir}/build-shared-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
